<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第一题</title>
</head>

<body>
    <script>
        let arr = []
        let j = 0
        while (true) {
            let age = +prompt(`请输入第${j + 1}个人的年龄`)
            if (age > 0 && age <= 100) {
                arr.push(age)
                j++
                if (j == 5) {
                    j == 5
                    break
                }
            } else {
                alert('请输入正确的年龄')
            }
        }
        // console.log(arr)
        arr.sort(function (a, b) {
            return b - a
        })
        console.log(arr)
        let num = 0
        let ave = 0

        for (let i = 0; i < arr.length; i++) {
            num += arr[i]
            if (arr[i] > 18) {
                document.write(`大于18岁的第${i + 1}个人的年龄为：${arr[i]}<br>`)
            }
        }
        ave = num / arr.length
        document.write(`
        五个人年龄的综合为${num}</br>
        平均年龄为:${ave}</br>
        最大年龄为：${arr[0]}</br>
        最小年龄为：${arr[4]}`)
    </script>
</body>

</html>